//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace OpenLS.Drawing.Serialization
{
    sealed class HyperlinkReader
    {
        public void AddAction(string s, Action<object> action)
        {
            if (s.Contains("lide0"))
                Debugger.Break();
            
            _actions.Add(new UriAndAction {Action = action, Uri = s});
        }

        sealed class UriAndAction
        {
            public string Uri;
            public Action<object> Action;
        }

        readonly List<UriAndAction> _actions = new List<UriAndAction>();
        readonly Dictionary<string, object> _uriToObject = new Dictionary<string, object>();
        public void Add (object target, string uri)
        {
            _uriToObject.Add(uri, target);
        }

        public void Resolve()
        {
            foreach (UriAndAction action in _actions)
            {
                object o = _uriToObject[action.Uri];
                action.Action(o);
            }
            
        }
    }
}